#W4_2
def sentence_split(string:str):
    puc_set = set(',.?!;:')
    nospace_str = string.split()
    for i,substr in enumerate(nospace_str):
        for letter in substr:
            if letter in puc_set:
                nospace_str[i] = substr.partition(letter)
                break
    return nospace_str
def reverse_nospace_str(nonspace_string:list):
    length = len(nonspace_string)
    ans_str = ''
    for i in range(length-1,-1,-1):
        sep = '' if i == length-1 else ' '
        substr = nonspace_string[i] if isinstance(nonspace_string[i],str) else ''.join(nonspace_string[i][-1: :-1])
        ans_str = ans_str + sep + substr
    return ans_str
def reverse_sentence(string:str):
    nonspace_string = sentence_split(string)
    return reverse_nospace_str(nonspace_string)
    

s1 = "I'm a happy guy,drving a car with a cool name:'Legend'"

reverse_sentence(s1)
